<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>xeokit Example</title>
    <link href="../css/pageStyle.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
    <style>

        /* ----------------------------------------------------------------------------------------------------------*/
        /* NavCubePlugin */
        /* ----------------------------------------------------------------------------------------------------------*/

        #myNavCubeCanvas {
            position: absolute;
            width: 250px;
            height: 250px;
            bottom: 50px;
            right: 10px;
            z-index: 200000;
        }
    </style>
</head>
<body>
<input type="checkbox" id="info-button"/>
<label for="info-button" class="info-button"><i class="far fa-3x fa-question-circle"></i></label>
<canvas id="myCanvas"></canvas>
<canvas id="myNavCubeCanvas"></canvas>
<div class="slideout-sidebar">
    <img class="info-icon" src="../../assets/images/bim_icon.png"/>
    <h1>WebIFCLoaderPlugin</h1>
    <h2>Loading an IFC File</h2>
    <p>This IFC model is placed at <code>[1842022,10,-5173301]</code>, but thanks to xeokit's double-precision
        coordinate support, we are able to render it without rounding jitter, without needing to center the model.</p>
    <p><a href="../../docs/class/src/plugins/WebIFCLoaderPlugin/WebIFCLoaderPlugin.js~WebIFCLoaderPlugin.html"
          target="_other">WebIFCLoaderPlugin</a> is the easiest way to loads IFC models with xeokit.</p>

    <h3>Limitations</h3>
    <p>WebIFCLoaderPlugin loads IFC STEP files and parses them within the browser using <a
            href="https://github.com/tomvandig/web-ifc"
            target="_other">web-ifc</a>, to create 3D objects within the
        Viewer.</p>
    <p>Loading and parsing huge IFC STEP files can be slow, and can overwhelm the browser, however. To view your
        largest IFC models, we recommend instead pre-converting those to xeokit's compressed native .XKT format, then
        loading them with <a href="../../docs/class/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js~XKTLoaderPlugin.html"
                               target="_other">XKTLoaderPlugin</a>.</p>
    <h3>Stats</h3>
    <ul>
        <li>
            <div id="time">Loading JavaScript modules...</div>
        </li>
    </ul>
    <h3>Components used</h3>
    <ul>
        <li>
            <a href="../../docs/class/src/viewer/Viewer.js~Viewer.html"
               target="_other">Viewer</a>
        </li>
        <li>
            <a href="../../docs/class/src/plugins/WebIFCLoaderPlugin/WebIFCLoaderPlugin.js~WebIFCLoaderPlugin.html"
               target="_other">WebIFCLoaderPlugin</a>
        </li>
        <li>
            <a href="../../docs/class/src/plugins/NavCubePlugin/NavCubePlugin.js~NavCubePlugin.html"
               target="_other">NavCubePlugin</a>
        </li>
    </ul>
    <h3>Assets</h3>
    <ul>
        <li>Model provided by <a href="https://bimdata.io" target="_other">BIMData.io</a></li>
    </ul>
</div>
</body>

<script type="module">

    import {Viewer, WebIFCLoaderPlugin, NavCubePlugin, FastNavPlugin} from "../../dist/xeokit-sdk.min.es.js";
    import * as WebIFC from "https://cdn.jsdelivr.net/npm/web-ifc@0.0.51/web-ifc-api.js";

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true,
        saoEnabled: true,
        dtxEnabled: true // Enable data texture model representation
    });

    // Higher-quality SAO settings
    const sao = viewer.scene.sao;
    sao.enabled = true;
    sao.numSamples = 40;
    sao.kernelRadius = 150;

    viewer.scene.camera.eye = [1841976.8512992272, 189.3586755924445, -5173296.766479015];
    viewer.scene.camera.look = [1842022.2895131256, 168.80595331576663, -5173301.847852854];
    viewer.scene.camera.up = [0.40746083837248614, 0.9120851705440081, -0.04556651036120888];

    new NavCubePlugin(viewer, {
        canvasId: "myNavCubeCanvas",
        visible: true,
        size: 250,
        alignment: "bottomRight",
        bottomMargin: 100,
        rightMargin: 10
    });

    new FastNavPlugin(viewer, {});

    const IfcAPI = new WebIFC.IfcAPI();

    IfcAPI.SetWasmPath("https://cdn.jsdelivr.net/npm/web-ifc@0.0.51/");

    IfcAPI.Init().then(() => {

        const ifcLoader = new WebIFCLoaderPlugin(viewer, {
            WebIFC,
            IfcAPI
        });
        const sceneModel = ifcLoader.load({
            id: "myModel",
            src: "../../assets/models/ifc/19_rue_Marc_Antoine_Petit_Ground_floor.ifc",
            loadMetadata: false,
            edges: true
        });

        sceneModel.on("loaded", () => {
            viewer.cameraFlight.jumpTo(sceneModel);
        });

        const t0 = performance.now();
        document.getElementById("time").innerHTML = "Loading model...";
        sceneModel.on("loaded", function () {
            const t1 = performance.now();
            document.getElementById("time").innerHTML = "Model loaded in " + Math.floor(t1 - t0) / 1000.0 + " seconds<br>Objects: " + sceneModel.numEntities;
        });

        window.viewer = viewer;

    });
</script>
</html>
